package com.xiaotu.web.struts2.person;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ActionSupport;
import com.xiaotu.code.model.person.Psn;
import com.xiaotu.code.service.person.PsnService;
import com.xiaotu.code.util.Struts2Util;

@Results( {
		@Result(name = "welcome", location = "/WEB-INF/content/welcome.jsp"),
		@Result(name = "navigation", location = "/WEB-INF/content/navigation.jsp") })
public class PsnAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = -432142367045478157L;
	protected Logger logger = LoggerFactory.getLogger(this.getClass());
	@Autowired
	private PsnService psnService;
	private String name;
	private String pw;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPw() {
		return pw;
	}

	public void setPw(String pw) {
		this.pw = pw;
	}

	@Action("/enter")
	public String login() throws Exception {
		logger.info("struts2日志测试");
		Psn psn = psnService.login(name);
		System.out.println("maven ssh测试:" + psn.getName());
		return "welcome";
	}
	
	@Action("/notice")
	public String notice()throws Exception{
		logger.info("测试jms");
		psnService.testJms();
		HttpServletResponse response=Struts2Util.getResponse();
		response.setContentType("text/html");
		response.setCharacterEncoding("UTF-8");
		response.getWriter().print("已发送消息");
		return null;
	}

	@Action("/navigation")
	public String navigation() throws Exception {
		return "navigation";
	}
}
